﻿using System.Collections.Generic;
using Core.DataAccess.Interfaces;
using Core.DataAccess.Tools.Interfaces;
using Core.Model;

namespace Core.DataAccess.Implementations
{
    public class UserDataProvider:ModelDataProvider<User>,IUserDataProvider
    {

        #region Implementation of IUserDataProvider

        public UserDataProvider(IConversation conversation, IRepository<User> repository) : base(conversation, repository)
        {
        }


        #endregion

        #region Implementation of IUserDataProvider

        public IList<User> GetUserByEmail(string email)
        {
            Conversation.Resume();
            var criteria = Conversation.Session.QueryOver<User>().Where(x =>
                x.Email == email).List<User>();
            Conversation.Pause();
            return criteria;
        }

        public User GetUserByName(string userName)
        {
            Conversation.Resume();
            var criteria = Conversation.Session.QueryOver<User>().Where(x =>
                x.UserName == userName).SingleOrDefault<User>();
            Conversation.Pause();
            return criteria;
        }

        #endregion
    }
}
